package br.ufscar.dc.zeus.controller;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

import br.ufscar.dc.zeus.interfaces.ICommand;

/**
 * Gerencia as acoes do formulario principal (o formulario
 * que contem o campo de texto para que a URL seja digitada).
 * As acoes sao:
 *     - Voltar: simplesmete retorna o foco para a caixa de texto
 *     - Cancelar: fecha a aplicacao
 *     - Download: inicia o download da URL digitada
 * 
 * @author Rodrigo
 * */
public class FormViewCommandListener implements CommandListener {

	public void commandAction( Command c, Displayable d ) {
		ICommand command = null;

		switch( c.getCommandType() ) {
			case Command.OK:
				command = new FormViewDownloadCommand();
				break;
			case Command.BACK:
				command = new FormViewBackCommand();
				break;
			case Command.CANCEL:
				command = new FormViewCancelCommand();
				break;
		}

		if( command != null ) {
			command.execute();
		}
	}

	public static FormViewCommandListener getInstance() {
		return FormViewCommandListenerSingletonHolder.instance;
	}

	private static class FormViewCommandListenerSingletonHolder {
		private static FormViewCommandListener instance = new FormViewCommandListener();
	}

}
